package com.link.base.tencent.corpwx.externalcontact.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.link.core.basic.annotations.JsonParam;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.base.tencent.corpwx.externalcontact.model.UnassignedAccount;
import com.link.base.tencent.corpwx.externalcontact.service.UnassignedAccountService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 离职人员客户-离职员工的客户列表 
 *
 * @author 李宗庭
 * @date 2020/01/15 10:21
 */
@Controller
@RequestMapping("/link/corpwx/unassignedAccount")
public class UnassignedAccountController extends BasicController<UnassignedAccount> {

    @Resource
    private UnassignedAccountService unassignedAccountService;

    @Override
    public BasicService<UnassignedAccount> getBasicService() throws Exception {
        return unassignedAccountService;
    }

    /**
     * 从企业微信同步离职人员的客户联系人到CRM
     * @author 李宗庭
     * @date 2020/01/15
     */
    @GetMapping(value = "/syncUnassignedAccountFromWx", name = "从企业微信同步离职人员的客户联系人到CRM")
    @ResponseBody
    public Map<String, Object> syncAllAccountInfo(HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            unassignedAccountService.syncUnassignedAccountFromWx();
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
    
    /** 
    * 离职人员客户再分配
    * @author Lizongting
    * @date 2020/1/15
    */
    @PostMapping(value = "/reassignAccount", name = "离职人员客户再分配")
    @ResponseBody
    public Map<String, Object> reassignAccount(@JsonParam UnassignedAccount record, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            unassignedAccountService.reassignAccount(record);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
